<?php


/**
 * Base class that represents a query for the 'users' table.
 *
 *
 *
 * @method UsersQuery orderById($order = Criteria::ASC) Order by the id column
 * @method UsersQuery orderByUserGroupId($order = Criteria::ASC) Order by the user_group_id column
 * @method UsersQuery orderByFname($order = Criteria::ASC) Order by the fname column
 * @method UsersQuery orderByLname($order = Criteria::ASC) Order by the lname column
 * @method UsersQuery orderByEmail($order = Criteria::ASC) Order by the email column
 * @method UsersQuery orderByOptionalEmail($order = Criteria::ASC) Order by the optional_email column
 * @method UsersQuery orderByCompany($order = Criteria::ASC) Order by the company column
 * @method UsersQuery orderByDepartment($order = Criteria::ASC) Order by the department column
 * @method UsersQuery orderByPhone($order = Criteria::ASC) Order by the phone column
 * @method UsersQuery orderByMobile($order = Criteria::ASC) Order by the mobile column
 * @method UsersQuery orderByPhoto($order = Criteria::ASC) Order by the photo column
 * @method UsersQuery orderByAdLogin($order = Criteria::ASC) Order by the ad_login column
 * @method UsersQuery orderByRole($order = Criteria::ASC) Order by the role column
 * @method UsersQuery orderByDeleted($order = Criteria::ASC) Order by the deleted column
 * @method UsersQuery orderByActive($order = Criteria::ASC) Order by the active column
 * @method UsersQuery orderByLastModified($order = Criteria::ASC) Order by the last_modified column
 * @method UsersQuery orderByCreated($order = Criteria::ASC) Order by the created column
 *
 * @method UsersQuery groupById() Group by the id column
 * @method UsersQuery groupByUserGroupId() Group by the user_group_id column
 * @method UsersQuery groupByFname() Group by the fname column
 * @method UsersQuery groupByLname() Group by the lname column
 * @method UsersQuery groupByEmail() Group by the email column
 * @method UsersQuery groupByOptionalEmail() Group by the optional_email column
 * @method UsersQuery groupByCompany() Group by the company column
 * @method UsersQuery groupByDepartment() Group by the department column
 * @method UsersQuery groupByPhone() Group by the phone column
 * @method UsersQuery groupByMobile() Group by the mobile column
 * @method UsersQuery groupByPhoto() Group by the photo column
 * @method UsersQuery groupByAdLogin() Group by the ad_login column
 * @method UsersQuery groupByRole() Group by the role column
 * @method UsersQuery groupByDeleted() Group by the deleted column
 * @method UsersQuery groupByActive() Group by the active column
 * @method UsersQuery groupByLastModified() Group by the last_modified column
 * @method UsersQuery groupByCreated() Group by the created column
 *
 * @method UsersQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method UsersQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method UsersQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method UsersQuery leftJoinUserGroups($relationAlias = null) Adds a LEFT JOIN clause to the query using the UserGroups relation
 * @method UsersQuery rightJoinUserGroups($relationAlias = null) Adds a RIGHT JOIN clause to the query using the UserGroups relation
 * @method UsersQuery innerJoinUserGroups($relationAlias = null) Adds a INNER JOIN clause to the query using the UserGroups relation
 *
 * @method UsersQuery leftJoinAuthHistory($relationAlias = null) Adds a LEFT JOIN clause to the query using the AuthHistory relation
 * @method UsersQuery rightJoinAuthHistory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the AuthHistory relation
 * @method UsersQuery innerJoinAuthHistory($relationAlias = null) Adds a INNER JOIN clause to the query using the AuthHistory relation
 *
 * @method UsersQuery leftJoinUserPulpit($relationAlias = null) Adds a LEFT JOIN clause to the query using the UserPulpit relation
 * @method UsersQuery rightJoinUserPulpit($relationAlias = null) Adds a RIGHT JOIN clause to the query using the UserPulpit relation
 * @method UsersQuery innerJoinUserPulpit($relationAlias = null) Adds a INNER JOIN clause to the query using the UserPulpit relation
 *
 * @method UsersQuery leftJoinUserApplicationData($relationAlias = null) Adds a LEFT JOIN clause to the query using the UserApplicationData relation
 * @method UsersQuery rightJoinUserApplicationData($relationAlias = null) Adds a RIGHT JOIN clause to the query using the UserApplicationData relation
 * @method UsersQuery innerJoinUserApplicationData($relationAlias = null) Adds a INNER JOIN clause to the query using the UserApplicationData relation
 *
 * @method Users findOne(PropelPDO $con = null) Return the first Users matching the query
 * @method Users findOneOrCreate(PropelPDO $con = null) Return the first Users matching the query, or a new Users object populated from the query conditions when no match is found
 *
 * @method Users findOneById(int $id) Return the first Users filtered by the id column
 * @method Users findOneByUserGroupId(int $user_group_id) Return the first Users filtered by the user_group_id column
 * @method Users findOneByFname(string $fname) Return the first Users filtered by the fname column
 * @method Users findOneByLname(string $lname) Return the first Users filtered by the lname column
 * @method Users findOneByEmail(string $email) Return the first Users filtered by the email column
 * @method Users findOneByOptionalEmail(string $optional_email) Return the first Users filtered by the optional_email column
 * @method Users findOneByCompany(string $company) Return the first Users filtered by the company column
 * @method Users findOneByDepartment(string $department) Return the first Users filtered by the department column
 * @method Users findOneByPhone(string $phone) Return the first Users filtered by the phone column
 * @method Users findOneByMobile(string $mobile) Return the first Users filtered by the mobile column
 * @method Users findOneByPhoto(string $photo) Return the first Users filtered by the photo column
 * @method Users findOneByAdLogin(string $ad_login) Return the first Users filtered by the ad_login column
 * @method Users findOneByRole(int $role) Return the first Users filtered by the role column
 * @method Users findOneByDeleted(string $deleted) Return the first Users filtered by the deleted column
 * @method Users findOneByActive(int $active) Return the first Users filtered by the active column
 * @method Users findOneByLastModified(string $last_modified) Return the first Users filtered by the last_modified column
 * @method Users findOneByCreated(string $created) Return the first Users filtered by the created column
 *
 * @method array findById(int $id) Return Users objects filtered by the id column
 * @method array findByUserGroupId(int $user_group_id) Return Users objects filtered by the user_group_id column
 * @method array findByFname(string $fname) Return Users objects filtered by the fname column
 * @method array findByLname(string $lname) Return Users objects filtered by the lname column
 * @method array findByEmail(string $email) Return Users objects filtered by the email column
 * @method array findByOptionalEmail(string $optional_email) Return Users objects filtered by the optional_email column
 * @method array findByCompany(string $company) Return Users objects filtered by the company column
 * @method array findByDepartment(string $department) Return Users objects filtered by the department column
 * @method array findByPhone(string $phone) Return Users objects filtered by the phone column
 * @method array findByMobile(string $mobile) Return Users objects filtered by the mobile column
 * @method array findByPhoto(string $photo) Return Users objects filtered by the photo column
 * @method array findByAdLogin(string $ad_login) Return Users objects filtered by the ad_login column
 * @method array findByRole(int $role) Return Users objects filtered by the role column
 * @method array findByDeleted(string $deleted) Return Users objects filtered by the deleted column
 * @method array findByActive(int $active) Return Users objects filtered by the active column
 * @method array findByLastModified(string $last_modified) Return Users objects filtered by the last_modified column
 * @method array findByCreated(string $created) Return Users objects filtered by the created column
 *
 * @package    propel.generator..om
 */
abstract class BaseUsersQuery extends ModelCriteria
{
    /**
     * Initializes internal state of BaseUsersQuery object.
     *
     * @param     string $dbName The dabase name
     * @param     string $modelName The phpName of a model, e.g. 'Book'
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     */
    public function __construct($dbName = 'vgp_hr_app', $modelName = 'Users', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }

    /**
     * Returns a new UsersQuery object.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param     UsersQuery|Criteria $criteria Optional Criteria to build the query from
     *
     * @return UsersQuery
     */
    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof UsersQuery) {
            return $criteria;
        }
        $query = new UsersQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    /**
     * Find object by primary key.
     * Propel uses the instance pool to skip the database if the object exists.
     * Go fast if the query is untouched.
     *
     * <code>
     * $obj  = $c->findPk(12, $con);
     * </code>
     *
     * @param mixed $key Primary key to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return   Users|Users[]|mixed the result, formatted by the current formatter
     */
    public function findPk($key, $con = null)
    {
        if ($key === null) {
            return null;
        }
        if ((null !== ($obj = UsersPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
            // the object is alredy in the instance pool
            return $obj;
        }
        if ($con === null) {
            $con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
         || $this->map || $this->having || $this->joins) {
            return $this->findPkComplex($key, $con);
        } else {
            return $this->findPkSimple($key, $con);
        }
    }

    /**
     * Find object by primary key using raw SQL to go fast.
     * Bypass doSelect() and the object formatter by using generated code.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return   Users A model object, or null if the key is not found
     * @throws   PropelException
     */
    protected function findPkSimple($key, $con)
    {
        $sql = 'SELECT ID, USER_GROUP_ID, FNAME, LNAME, EMAIL, OPTIONAL_EMAIL, COMPANY, DEPARTMENT, PHONE, MOBILE, PHOTO, AD_LOGIN, ROLE, DELETED, ACTIVE, LAST_MODIFIED, CREATED FROM users WHERE ID = :p0';
        try {
            $stmt = $con->prepare($sql);
            $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
            $stmt->execute();
        } catch (Exception $e) {
            Propel::log($e->getMessage(), Propel::LOG_ERR);
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
        }
        $obj = null;
        if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            $obj = new Users();
            $obj->hydrate($row);
            UsersPeer::addInstanceToPool($obj, (string) $key);
        }
        $stmt->closeCursor();

        return $obj;
    }

    /**
     * Find object by primary key.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return Users|Users[]|mixed the result, formatted by the current formatter
     */
    protected function findPkComplex($key, $con)
    {
        // As the query uses a PK condition, no limit(1) is necessary.
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKey($key)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
    }

    /**
     * Find objects by primary key
     * <code>
     * $objs = $c->findPks(array(12, 56, 832), $con);
     * </code>
     * @param     array $keys Primary keys to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return PropelObjectCollection|Users[]|mixed the list of results, formatted by the current formatter
     */
    public function findPks($keys, $con = null)
    {
        if ($con === null) {
            $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKeys($keys)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->format($stmt);
    }

    /**
     * Filter the query by primary key
     *
     * @param     mixed $key Primary key to use for the query
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByPrimaryKey($key)
    {

        return $this->addUsingAlias(UsersPeer::ID, $key, Criteria::EQUAL);
    }

    /**
     * Filter the query by a list of primary keys
     *
     * @param     array $keys The list of primary key to use for the query
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByPrimaryKeys($keys)
    {

        return $this->addUsingAlias(UsersPeer::ID, $keys, Criteria::IN);
    }

    /**
     * Filter the query on the id column
     *
     * Example usage:
     * <code>
     * $query->filterById(1234); // WHERE id = 1234
     * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
     * $query->filterById(array('min' => 12)); // WHERE id > 12
     * </code>
     *
     * @param     mixed $id The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterById($id = null, $comparison = null)
    {
        if (is_array($id) && null === $comparison) {
            $comparison = Criteria::IN;
        }

        return $this->addUsingAlias(UsersPeer::ID, $id, $comparison);
    }

    /**
     * Filter the query on the user_group_id column
     *
     * Example usage:
     * <code>
     * $query->filterByUserGroupId(1234); // WHERE user_group_id = 1234
     * $query->filterByUserGroupId(array(12, 34)); // WHERE user_group_id IN (12, 34)
     * $query->filterByUserGroupId(array('min' => 12)); // WHERE user_group_id > 12
     * </code>
     *
     * @see       filterByUserGroups()
     *
     * @param     mixed $userGroupId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByUserGroupId($userGroupId = null, $comparison = null)
    {
        if (is_array($userGroupId)) {
            $useMinMax = false;
            if (isset($userGroupId['min'])) {
                $this->addUsingAlias(UsersPeer::USER_GROUP_ID, $userGroupId['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($userGroupId['max'])) {
                $this->addUsingAlias(UsersPeer::USER_GROUP_ID, $userGroupId['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(UsersPeer::USER_GROUP_ID, $userGroupId, $comparison);
    }

    /**
     * Filter the query on the fname column
     *
     * Example usage:
     * <code>
     * $query->filterByFname('fooValue');   // WHERE fname = 'fooValue'
     * $query->filterByFname('%fooValue%'); // WHERE fname LIKE '%fooValue%'
     * </code>
     *
     * @param     string $fname The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByFname($fname = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($fname)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $fname)) {
                $fname = str_replace('*', '%', $fname);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::FNAME, $fname, $comparison);
    }

    /**
     * Filter the query on the lname column
     *
     * Example usage:
     * <code>
     * $query->filterByLname('fooValue');   // WHERE lname = 'fooValue'
     * $query->filterByLname('%fooValue%'); // WHERE lname LIKE '%fooValue%'
     * </code>
     *
     * @param     string $lname The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByLname($lname = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($lname)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $lname)) {
                $lname = str_replace('*', '%', $lname);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::LNAME, $lname, $comparison);
    }

    /**
     * Filter the query on the email column
     *
     * Example usage:
     * <code>
     * $query->filterByEmail('fooValue');   // WHERE email = 'fooValue'
     * $query->filterByEmail('%fooValue%'); // WHERE email LIKE '%fooValue%'
     * </code>
     *
     * @param     string $email The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByEmail($email = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($email)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $email)) {
                $email = str_replace('*', '%', $email);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::EMAIL, $email, $comparison);
    }

    /**
     * Filter the query on the optional_email column
     *
     * Example usage:
     * <code>
     * $query->filterByOptionalEmail('fooValue');   // WHERE optional_email = 'fooValue'
     * $query->filterByOptionalEmail('%fooValue%'); // WHERE optional_email LIKE '%fooValue%'
     * </code>
     *
     * @param     string $optionalEmail The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByOptionalEmail($optionalEmail = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($optionalEmail)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $optionalEmail)) {
                $optionalEmail = str_replace('*', '%', $optionalEmail);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::OPTIONAL_EMAIL, $optionalEmail, $comparison);
    }

    /**
     * Filter the query on the company column
     *
     * Example usage:
     * <code>
     * $query->filterByCompany('fooValue');   // WHERE company = 'fooValue'
     * $query->filterByCompany('%fooValue%'); // WHERE company LIKE '%fooValue%'
     * </code>
     *
     * @param     string $company The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByCompany($company = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($company)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $company)) {
                $company = str_replace('*', '%', $company);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::COMPANY, $company, $comparison);
    }

    /**
     * Filter the query on the department column
     *
     * Example usage:
     * <code>
     * $query->filterByDepartment('fooValue');   // WHERE department = 'fooValue'
     * $query->filterByDepartment('%fooValue%'); // WHERE department LIKE '%fooValue%'
     * </code>
     *
     * @param     string $department The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByDepartment($department = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($department)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $department)) {
                $department = str_replace('*', '%', $department);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::DEPARTMENT, $department, $comparison);
    }

    /**
     * Filter the query on the phone column
     *
     * Example usage:
     * <code>
     * $query->filterByPhone('fooValue');   // WHERE phone = 'fooValue'
     * $query->filterByPhone('%fooValue%'); // WHERE phone LIKE '%fooValue%'
     * </code>
     *
     * @param     string $phone The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByPhone($phone = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($phone)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $phone)) {
                $phone = str_replace('*', '%', $phone);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::PHONE, $phone, $comparison);
    }

    /**
     * Filter the query on the mobile column
     *
     * Example usage:
     * <code>
     * $query->filterByMobile('fooValue');   // WHERE mobile = 'fooValue'
     * $query->filterByMobile('%fooValue%'); // WHERE mobile LIKE '%fooValue%'
     * </code>
     *
     * @param     string $mobile The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByMobile($mobile = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($mobile)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $mobile)) {
                $mobile = str_replace('*', '%', $mobile);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::MOBILE, $mobile, $comparison);
    }

    /**
     * Filter the query on the photo column
     *
     * Example usage:
     * <code>
     * $query->filterByPhoto('fooValue');   // WHERE photo = 'fooValue'
     * $query->filterByPhoto('%fooValue%'); // WHERE photo LIKE '%fooValue%'
     * </code>
     *
     * @param     string $photo The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByPhoto($photo = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($photo)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $photo)) {
                $photo = str_replace('*', '%', $photo);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::PHOTO, $photo, $comparison);
    }

    /**
     * Filter the query on the ad_login column
     *
     * Example usage:
     * <code>
     * $query->filterByAdLogin('fooValue');   // WHERE ad_login = 'fooValue'
     * $query->filterByAdLogin('%fooValue%'); // WHERE ad_login LIKE '%fooValue%'
     * </code>
     *
     * @param     string $adLogin The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByAdLogin($adLogin = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($adLogin)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $adLogin)) {
                $adLogin = str_replace('*', '%', $adLogin);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(UsersPeer::AD_LOGIN, $adLogin, $comparison);
    }

    /**
     * Filter the query on the role column
     *
     * Example usage:
     * <code>
     * $query->filterByRole(1234); // WHERE role = 1234
     * $query->filterByRole(array(12, 34)); // WHERE role IN (12, 34)
     * $query->filterByRole(array('min' => 12)); // WHERE role > 12
     * </code>
     *
     * @param     mixed $role The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByRole($role = null, $comparison = null)
    {
        if (is_array($role)) {
            $useMinMax = false;
            if (isset($role['min'])) {
                $this->addUsingAlias(UsersPeer::ROLE, $role['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($role['max'])) {
                $this->addUsingAlias(UsersPeer::ROLE, $role['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(UsersPeer::ROLE, $role, $comparison);
    }

    /**
     * Filter the query on the deleted column
     *
     * Example usage:
     * <code>
     * $query->filterByDeleted('2011-03-14'); // WHERE deleted = '2011-03-14'
     * $query->filterByDeleted('now'); // WHERE deleted = '2011-03-14'
     * $query->filterByDeleted(array('max' => 'yesterday')); // WHERE deleted > '2011-03-13'
     * </code>
     *
     * @param     mixed $deleted The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByDeleted($deleted = null, $comparison = null)
    {
        if (is_array($deleted)) {
            $useMinMax = false;
            if (isset($deleted['min'])) {
                $this->addUsingAlias(UsersPeer::DELETED, $deleted['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($deleted['max'])) {
                $this->addUsingAlias(UsersPeer::DELETED, $deleted['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(UsersPeer::DELETED, $deleted, $comparison);
    }

    /**
     * Filter the query on the active column
     *
     * Example usage:
     * <code>
     * $query->filterByActive(1234); // WHERE active = 1234
     * $query->filterByActive(array(12, 34)); // WHERE active IN (12, 34)
     * $query->filterByActive(array('min' => 12)); // WHERE active > 12
     * </code>
     *
     * @param     mixed $active The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByActive($active = null, $comparison = null)
    {
        if (is_array($active)) {
            $useMinMax = false;
            if (isset($active['min'])) {
                $this->addUsingAlias(UsersPeer::ACTIVE, $active['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($active['max'])) {
                $this->addUsingAlias(UsersPeer::ACTIVE, $active['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(UsersPeer::ACTIVE, $active, $comparison);
    }

    /**
     * Filter the query on the last_modified column
     *
     * Example usage:
     * <code>
     * $query->filterByLastModified('2011-03-14'); // WHERE last_modified = '2011-03-14'
     * $query->filterByLastModified('now'); // WHERE last_modified = '2011-03-14'
     * $query->filterByLastModified(array('max' => 'yesterday')); // WHERE last_modified > '2011-03-13'
     * </code>
     *
     * @param     mixed $lastModified The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByLastModified($lastModified = null, $comparison = null)
    {
        if (is_array($lastModified)) {
            $useMinMax = false;
            if (isset($lastModified['min'])) {
                $this->addUsingAlias(UsersPeer::LAST_MODIFIED, $lastModified['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($lastModified['max'])) {
                $this->addUsingAlias(UsersPeer::LAST_MODIFIED, $lastModified['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(UsersPeer::LAST_MODIFIED, $lastModified, $comparison);
    }

    /**
     * Filter the query on the created column
     *
     * Example usage:
     * <code>
     * $query->filterByCreated('2011-03-14'); // WHERE created = '2011-03-14'
     * $query->filterByCreated('now'); // WHERE created = '2011-03-14'
     * $query->filterByCreated(array('max' => 'yesterday')); // WHERE created > '2011-03-13'
     * </code>
     *
     * @param     mixed $created The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function filterByCreated($created = null, $comparison = null)
    {
        if (is_array($created)) {
            $useMinMax = false;
            if (isset($created['min'])) {
                $this->addUsingAlias(UsersPeer::CREATED, $created['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($created['max'])) {
                $this->addUsingAlias(UsersPeer::CREATED, $created['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(UsersPeer::CREATED, $created, $comparison);
    }

    /**
     * Filter the query by a related UserGroups object
     *
     * @param   UserGroups|PropelObjectCollection $userGroups The related object(s) to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   UsersQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUserGroups($userGroups, $comparison = null)
    {
        if ($userGroups instanceof UserGroups) {
            return $this
                ->addUsingAlias(UsersPeer::USER_GROUP_ID, $userGroups->getId(), $comparison);
        } elseif ($userGroups instanceof PropelObjectCollection) {
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }

            return $this
                ->addUsingAlias(UsersPeer::USER_GROUP_ID, $userGroups->toKeyValue('PrimaryKey', 'Id'), $comparison);
        } else {
            throw new PropelException('filterByUserGroups() only accepts arguments of type UserGroups or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the UserGroups relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function joinUserGroups($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('UserGroups');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'UserGroups');
        }

        return $this;
    }

    /**
     * Use the UserGroups relation UserGroups object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   UserGroupsQuery A secondary query class using the current class as primary query
     */
    public function useUserGroupsQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinUserGroups($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'UserGroups', 'UserGroupsQuery');
    }

    /**
     * Filter the query by a related AuthHistory object
     *
     * @param   AuthHistory|PropelObjectCollection $authHistory  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   UsersQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByAuthHistory($authHistory, $comparison = null)
    {
        if ($authHistory instanceof AuthHistory) {
            return $this
                ->addUsingAlias(UsersPeer::ID, $authHistory->getUserId(), $comparison);
        } elseif ($authHistory instanceof PropelObjectCollection) {
            return $this
                ->useAuthHistoryQuery()
                ->filterByPrimaryKeys($authHistory->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByAuthHistory() only accepts arguments of type AuthHistory or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the AuthHistory relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function joinAuthHistory($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('AuthHistory');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'AuthHistory');
        }

        return $this;
    }

    /**
     * Use the AuthHistory relation AuthHistory object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   AuthHistoryQuery A secondary query class using the current class as primary query
     */
    public function useAuthHistoryQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    {
        return $this
            ->joinAuthHistory($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'AuthHistory', 'AuthHistoryQuery');
    }

    /**
     * Filter the query by a related UserPulpit object
     *
     * @param   UserPulpit|PropelObjectCollection $userPulpit  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   UsersQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUserPulpit($userPulpit, $comparison = null)
    {
        if ($userPulpit instanceof UserPulpit) {
            return $this
                ->addUsingAlias(UsersPeer::ID, $userPulpit->getUserId(), $comparison);
        } elseif ($userPulpit instanceof PropelObjectCollection) {
            return $this
                ->useUserPulpitQuery()
                ->filterByPrimaryKeys($userPulpit->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByUserPulpit() only accepts arguments of type UserPulpit or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the UserPulpit relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function joinUserPulpit($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('UserPulpit');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'UserPulpit');
        }

        return $this;
    }

    /**
     * Use the UserPulpit relation UserPulpit object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   UserPulpitQuery A secondary query class using the current class as primary query
     */
    public function useUserPulpitQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinUserPulpit($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'UserPulpit', 'UserPulpitQuery');
    }

    /**
     * Filter the query by a related UserApplicationData object
     *
     * @param   UserApplicationData|PropelObjectCollection $userApplicationData  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   UsersQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUserApplicationData($userApplicationData, $comparison = null)
    {
        if ($userApplicationData instanceof UserApplicationData) {
            return $this
                ->addUsingAlias(UsersPeer::ID, $userApplicationData->getUserId(), $comparison);
        } elseif ($userApplicationData instanceof PropelObjectCollection) {
            return $this
                ->useUserApplicationDataQuery()
                ->filterByPrimaryKeys($userApplicationData->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByUserApplicationData() only accepts arguments of type UserApplicationData or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the UserApplicationData relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function joinUserApplicationData($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('UserApplicationData');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'UserApplicationData');
        }

        return $this;
    }

    /**
     * Use the UserApplicationData relation UserApplicationData object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   UserApplicationDataQuery A secondary query class using the current class as primary query
     */
    public function useUserApplicationDataQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinUserApplicationData($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'UserApplicationData', 'UserApplicationDataQuery');
    }

    /**
     * Exclude object from result
     *
     * @param   Users $users Object to remove from the list of results
     *
     * @return UsersQuery The current query, for fluid interface
     */
    public function prune($users = null)
    {
        if ($users) {
            $this->addUsingAlias(UsersPeer::ID, $users->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }

}
